<?php 
session_start();
if (isset($_SESSION['username'])) {
	$id = $_GET['id'];
	$data=file_get_contents("./Db/db.json");
	$data=json_decode($data,true);
	if (!empty($_POST)) {
		$data[$id]['addressee']=$_POST['addressee'];
		$data[$id]['content']=$_POST['content'];
		// $data[$id][]=$_POST;
		$data[$id]['ctime']=time();
		$data=json_encode($data);
		file_put_contents('./Db/db.json', $data);
		header("Location:./index.php");
	}
}else{
	header("Location:./index.php");
}

 ?>

 <html lang="en">
 <head>
 	<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
 	<title>编辑留言</title>
 	<link href="./Tpl/css/bootstrap.min.css" rel="stylesheet">
 </head>
 <body>
 	<nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="./index.php">留言板</a>
        </div>
      </div>
    </nav>
	 	<div class="container" style="padding-top:100px;">
		 	<form class="form-inline" action="./edit.php?id=<?php echo $_GET['id'] ?>" method="post">
		        <div class="form-group">
		          <label for="exampleInputName2">用户名</label>
		          <input type="text" class="form-control" id="exampleInputName2" name="addressee" placeholder="" value="<?php echo $data[$id]['addressee'];?>">
		        </div>

		        <button type="submit" style="float:right;margin-right:15px;" class="btn btn-success">保存</button>
		        <div class="col-md-12" style="padding-top:10px;padding-left:0px;">
		          <textarea name="content" class="form-control" style="width:100%" rows="3" placeholder=""><?php echo $data[$id]['content'];?></textarea>
		        </div>
		    </form>
	     </div>
 </body>
 </html>

